//
//  XLRefreshView.swift
//  DEMO01
//
//  Created by 张晓林 on 16/10/9.
//  Copyright © 2016年 张晓林. All rights reserved.
//

import UIKit

class XLRefreshView: UIView {
    
    // 定义一个枚举属性，来区别做什么事情
    // didSet 没法索引，类似于OC里面的setter方法
    var refreshState: XLRefreshState = .nomol {
        didSet {
            switch refreshState {
            case .nomol:
                // 先回复视图状态
                arrowView.isHidden = false
                activityView.stopAnimating()
                titleL.text = "恩.再用点儿力"
                UIView.animate(withDuration: 0.25, animations: { 
                    self.arrowView.transform = CGAffineTransform.identity
                })
            case .pulling:
                titleL.text = "放手就刷新数据"
                UIView.animate(withDuration: 0.25, animations: { 
                    self.arrowView.transform = CGAffineTransform(rotationAngle: CGFloat(M_PI) - 0.001)
                })
            case .willRefresh:
                titleL.text = "正在刷新数据..."
                arrowView.isHidden = true
                activityView.startAnimating()
            }
        }
    }

    @IBOutlet weak var arrowView: UIImageView!
    @IBOutlet weak var activityView: UIActivityIndicatorView!
    @IBOutlet weak var titleL: UILabel!
    
    class func refreshV() -> XLRefreshView {
        // 获取xib
        let xib = UINib(nibName: "XLRefreshGirlView", bundle: nil)
        // 获取视图
        return xib.instantiate(withOwner: nil, options: nil)[0] as! XLRefreshView
    }
}










